package com.cqs.leetcode.math;

public class RotatedDigits788 {

    public int[] canRotate = {0, 0, 1, -1, -1, 1, 1, -1, 0, 1};

    public int rotatedDigits(int n) {
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += isRotate(i);
        }
        return sum;
    }

    public int isRotate(int k) {
        int target = 0;
        while (k != 0) {
            if (canRotate[k % 10] == -1) {
                return 0;
            }
            target += canRotate[k % 10];
            k = k / 10;
        }
        return target > 0 ? 1 : 0;
    }


    public static void main(String[] args) {
        RotatedDigits788 s = new RotatedDigits788();
        for (int i = 10000; i <= 10000; i++) {
            System.out.println(i + "\t" + s.rotatedDigits(i));
        }
    }
}
